<script>
import { reactive, toRefs } from '@vue/reactivity';
  // <!-- 作者信息 -->
  import {getdetails} from "../api/author"
import { useRouter } from 'vue-router';
import { onMounted } from '@vue/runtime-core';
export default {
  setup() {
    const router = useRouter();

    let list = reactive({
      lists:null,//作者
      booksList:null,//作品
      shelfList:null,//书架
      threadList:null,//动态
    })
          getdetails().then(data=>{
      list.lists = data.data.userInfo
      list.booksList = data.data.books
      list.shelfList = data.data.shelf
      console.log(list.shelfList,'55');
      list.threadList = data.data.thread
         let commens = JSON.parse(localStorage.getItem("commens"))
          console.log(commens,'4');
        if (commens && commens.length) {
         for (let i = 0; i < list.threadList.lists.length; i++) {
              for (let j = 0; j < commens.length; j++) {
                if (list.threadList.lists[i].id == commens[j].emid) {
                  list.threadList.lists[i].replyCount += 1;
                }
              }
            }
        }
      console.log( list.threadList);
    })
    onMounted(()=>{

    })


    let btnFun = (id) =>{
      let index = list.threadList.lists.findIndex(item => item.id == id)
      console.log(list.threadList.lists[index].groupId);
      router.push('replies?id='+id+'&groupId='+list.threadList.lists[index].groupId)

    }


    return {
      ...toRefs(list),
      btnFun
    };
  },
};
</script>


<template>
  <div class="authorView">
    <header class="header">
        <div class="left" @click="$router.go(-1)"><i class="iconfont icon-zuojiantou-copy"></i></div>
      <div class="center">作者信息</div>
      <div class="left"><i class="iconfont icon-fenxiang"></i></div>
    </header>
    <nav v-if="lists">
      <div class="left">
        <img :src="lists.avatarUrl" alt="" />
      </div>
      <div class="right">
        <div class="top">
          <span>{{lists.penName}}<i>作者</i></span>
          <!-- <a>已关注</a> -->
        </div>
        <div class="center">
          <!-- <span>关注: <i>{{lists.follow}} </i></span> -->
          <span> 粉丝: <i>{{lists.followed}}</i></span>
          <!-- <a>已关注</a> -->
        </div>
        <p>{{lists.info}}</p>
      </div>
    </nav>
    <main>
      <div class="works" v-if="booksList">
        <p>Ta的作品({{booksList.length}})</p>
        <ul>
           <router-link  v-for="(item,index) in booksList" :key="index" custom :to="'/details?id=' + item.bookId" v-slot="{href , navigate}">
          <li @click="navigate" :href="href">
            <div class="img">
              <img :src="item.coverImg" alt="" />
            </div>
            <div class="name">{{item.bookName}}</div>
          </li>
           </router-link>
        </ul>
      </div>
      <div class="works" v-if="shelfList">
        <p>Ta的书架({{shelfList.length}})</p>
        <ul>
          <router-link v-for="(item,index) in shelfList"  :key="index" custom :to="'/details?id=' + item.bookId" v-slot="{href , navigate}">
          <li :href="href" @click="navigate">
            <div class="img">
              <img :src="item.coverImg" alt="" />
            </div>
            <div class="name">{{item.bookName}}</div>
          </li>
           </router-link>
        </ul>
      </div>
      <div class="dynamic" v-if="threadList">
        <h6>Ta 发布的动态</h6>
        <ul>
          <li v-for="(item,index) in threadList.lists" :key="index">
            <div class="top">
              <img :src="item.userInfo.avatarUrl" alt="" />
              <span>{{item.userInfo.nickname}}</span>
              <a>作者</a>
            </div>
            <p>{{item.summary}}</p>
            <div class="buttom">
              <div class="left">{{item.groupName}}</div>
              <div class="right">
                <span @click="btnFun(item.id)"><i class="iconfont icon-xiaoxi"></i>{{item.replyCount}}</span>
                <!-- <span :class="index == 0?'con':''"><i class="iconfont icon-dianzan"></i>{{item.praiseCount > 0?item.praiseCount:'赞'}}</span> -->
              </div>
            </div>
          </li>
        </ul>
      </div>
    </main>
  </div>
</template>


<style lang="scss" scoped>
.authorView {
  background-color: #f4f4f4;
  header {
    position: sticky;
    top: 0;
    left: 0;
    padding: 12px 15px;
    display: flex;
    justify-content: space-between;
    color: #fff;
    i {
      font-size: 22px;
    }
  }
  .header {
    background-color: #3b3b3b;
  }
  nav {
    background-color: #3b3b3b;
    padding: 10px 15px;
    display: flex;
    align-items: center;
    color: #eaeaea;
    .left {
      height: 44px;
      margin-right: 10px;
      img {
        border-radius: 50%;
        border: 2px solid #fff;
        height: 100%;
      }
    }
    .right {
      flex: 1;
      .top {
        display: flex;
        align-items: center;
        justify-content: space-between;
        font-size: 16px;
        i {
          border-radius: 7px;
          padding: 0 5px;
          font-size: 12px;
          display: inline-block;
          border: 1px solid #eaeaea;
        }
        span {
          i {
            margin-left: 5px;
            padding: 0 2px;
            font-size: 8px;
            background-color: #498fde;
          }
        }
      }
      .center {
        margin: 9px 0;
        font-size: 13px;
        span{
          margin-right: 10px;
        }
      }
      p {
        font-size: 13px;
        margin-bottom: 10px;
      }
    }
  }
  .works {
    padding: 0 15px 15px;
    background-color: #ffffff;
    margin-bottom: 10px;
    overflow: hidden;
    p {
      padding: 10px 0;
      font-size: 13px;
    }
    ul {
      display: flex;
          flex-wrap: wrap;
      font-size: 13px;
      box-sizing: border-box;
      li {
        margin-right: 15px;
        margin-top: 10px;
        font-size: 12px;
        color: #010606;
        .img {
          height: 102px;
          margin-bottom: 10px;
          img {
            height: 100%;
            border-radius: 6px;
          }
        }
        // .name {
        // }
      }
    }
  }
  .dynamic {
    padding: 0 0 15px;
    margin-bottom: 10px;
    h6 {
      background-color: #ffffff;
      font-size: 13px;
      font-weight: normal;
      padding: 10px 15px 0px;
    }
    ul {
      li {
        padding: 14px 15px;
        background-color: #ffffff;

        margin-bottom: 8px;
        .top {
          font-size: 12px;
          display: flex;
          align-items: center;
          margin-bottom: 12px;
          img {
            height: 20px;
            margin-right: 8px;
            border-radius: 50%;
          }
          a {
            margin-left: 10px;
            padding: 0 4px;
            font-size: 8px;
            color: #fff;
            border-radius: 8px;
            background-color: #498fde;
          }
        }
        p {
          font-size: 14px;
          color: #3f3f3f;
        }
        .buttom {
          padding-top:  14px;
          display: flex;
          font-size: 12px;
          justify-content: space-between;
          align-items: center;
          .left {
            border-radius: 20px;
            padding: 5px 12px;
            color: #19191b;
            background-color: #f6f6f8;
          }
          .right {
              span {
                  color: #262626;
              margin-left: 15px;
              i {
                  margin-right: 5px;
              }
            }
                  .con{
                      color: rgb(111, 224, 160);
                  }
          }
        }
      }
    }
  }
}
</style>